<?php

class PageTypeController extends GxController {

    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id, 'PageType'),
        ));
    }

    public function actionCreate() {
        $model = new PageType;

        if (isset($_POST['PageType'])) {
            $model->setAttributes($_POST['PageType']);

            if ($model->save()) {
                if (Yii::app()->getRequest()->getIsAjaxRequest())
                    Yii::app()->end();
                else
                    $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('create', array('model' => $model));
    }

    public function actioncmspage($page_title, $id) {
        $this->layout = 'innerpage';
        $abouContent = PageContent::model()->findByAttributes(array('id' => $id));
        if (!empty($abouContent)) {
            $this->pageTitle = 'Anti Ragging | ' . $abouContent->page_title;
            Yii::app()->clientScript->registerMetaTag($abouContent->meta_description, 'description');
            Yii::app()->clientScript->registerMetaTag($abouContent->meta_tag, 'keywords');
            Yii::app()->clientScript->registerMetaTag($this->createAbsoluteUrl('/amanmovent-' . $abouContent->id . '-' . $abouContent->page_title), '', null, array('id' => 'meta-url', 'property' => 'og:image'), 'meta_og_image');
            $this->render('cmspage', array('abouContent' => $abouContent));
        } else {
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
        }
    }

    public function actionUpdate($id) {
        $model = $this->loadModel($id, 'PageType');


        if (isset($_POST['PageType'])) {
            $model->setAttributes($_POST['PageType']);

            if ($model->save()) {
                $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('update', array(
            'model' => $model,
        ));
    }

    public function actionDelete($id) {
        if (Yii::app()->getRequest()->getIsPostRequest()) {
            $this->loadModel($id, 'PageType')->delete();

            if (!Yii::app()->getRequest()->getIsAjaxRequest())
                $this->redirect(array('admin'));
        } else
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
    }

    public function actionIndex() {
        $dataProvider = new CActiveDataProvider('PageType');
        $this->render('index', array(
            'dataProvider' => $dataProvider,
        ));
    }

    public function actionAdmin() {
        $model = new PageType('search');
        $model->unsetAttributes();

        if (isset($_GET['PageType']))
            $model->setAttributes($_GET['PageType']);

        $this->render('admin', array(
            'model' => $model,
        ));
    }

}
